package com.molin.networkTest.socketTest.demo3;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class ClientDemo {
    //UDP发送程序：数据来自于键盘录入，直到输入的数据是886，发送数据结束
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();
        Scanner sc=new Scanner(System.in);

        while (true) {
            System.out.println(Thread.currentThread().getName()+"说: ");
            String s = sc.nextLine();
            if("886".equals(s)){break;}
            byte[] bytes=s.getBytes();
            DatagramPacket packet=new DatagramPacket(bytes,bytes.length, InetAddress.getByName("127.0.0.1"),8888);
            socket.send(packet);
        }
        socket.close();
    }
}
